import {deepClone} from 'nc-lightapp-front';
import React from "react";
import getOnePsnData from "./getOnePsnData";

// 初始化处理template数据
export default function processTemplate(template) {
    let _that = this;
    Object.assign(template, {
        sort: {
            "moduletype": "table",
            "code": "sort",
            "name": this.state.json['hi6007-000068'], /* 国际化处理： 排序*/
            "items": [{
                "attrcode": "field_code",
                "color": "#6E6E77",
                "label": this.state.json['hi6007-000069'], /* 国际化处理： 排序字段*/
                "width": "140px",
                "visible": true
            }, {
                "attrcode": "ascend_flag",
                "color": "#6E6E77",
                "label": this.state.json['hi6007-000070'], /* 国际化处理： 升降序*/
                "width": "140px",
                "visible": true
            }]
        }
    });
    template['ncc60071702list'].items.forEach(item => {
        // item.width = '100px';
        if (item.attrcode === 'pk_psndoc.code') {
            item.render = (text, record, index) => {
                return (
                    <span
                        className="simple-table-title"
                        style={{color: '#007ace', cursor: 'pointer'}}
                        onClick={() => {
                            getOnePsnData.call(_that, this.state.orgVal, record.pk_psnjob.value, (data) => {
                                this.setState({
                                    page: 'detail',
                                    detailTemplate: data,
                                    isShowBottomDom: false
                                });
                            })
                        }}
                    >
                        {record && record['pk_psndoc.code'] && record['pk_psndoc.code'].value}
                    </span>
                );
            };
        }
    });

    template.hi_psnjob_history = deepClone(template.hi_psnjob);
    template.hi_psnjob_history.items.find(item => item.attrcode === 'ismainjob').visible = true;
    template.hi_psnjob_history_down = deepClone(template.hi_psnjob_history);
    return template
}
